package com.iweb.controller;

import com.common.context.RequestMapping;
import com.common.model.DataGrid;
import com.iweb.pojo.Travel;
import com.iweb.service.TravelService;
import com.iweb.utils.JsonUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Random;


@RequestMapping("travel")
public class TravelController {

    @RequestMapping("selectTravelSite")
    //根据title查询
    public String selectTravelSite(Travel travel, HttpServletRequest request){
        TravelService travelService = new TravelService();
        String title = null;

        if(travel != null){
            title = travel.getTitle();
        }

        List<Travel> list = travelService.selectTravelSite(title);
        int len = list.size();
        for (int i = 0; i < 10-len; i++) {
            list.add(list.get(new Random().nextInt(list.size())));
        }

        request.setAttribute("list",list);
        return "/travel/scenicSpotList.jsp";
    }

    @RequestMapping("selectById")
    public String selectById(Travel travel, HttpServletRequest request){
        TravelService travelService = new TravelService();
        Travel data = travelService.selectById(travel.getId());
       // JsonUtil.writeJsonStr(response,data);
        request.setAttribute("detail",data);

        return "/travel/travelMenuDetail.jsp";
    }
    @RequestMapping("findAllTravel")
    public String findAllTravel(Travel travel,HttpServletRequest request){
        TravelService travelService = new TravelService();
        List<Travel> list= travelService.findAllTravel();
        request.setAttribute("list",list);
//        System.out.println(list.size());
        return "/travel/all.jsp";
    }

}
